﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COFE.Core;

namespace COFE.Web
{
    public class XmlEntryList : EntryList
    {
        #region Constructor

        internal XmlEntryList(EntryListType eType, IEnumerable<Entry> initialEntries,
            Guid id, string name)
            : base(eType, id, name)
        {
            if (initialEntries != null)
                _entries = new List<Entry>(initialEntries);
            else _entries = new List<Entry>();
        }

        internal XmlEntryList(Guid id, string name)
            : this(EntryListType.Xml, null, id, name)
        {

        }

        public XmlEntryList(IEnumerable<Entry> initialEntries,
            Guid id, string name)
            : this(EntryListType.Xml, initialEntries, id, name)
        {

        }

        internal XmlEntryList(IEnumerable<IFileSystemInfo> initialEntries,
           Guid id, string name)
            : this(from e in initialEntries select Entry.FromCofeEntry(e),
                    id, name)
        {
        }

        public static XmlEntryList CreateTestEntryList(string name)
        {
            return new XmlEntryList(Guid.NewGuid(), name);
        }

        #endregion

        #region Methods

        protected override IEnumerable<Entry> getEntries()
        {
            lock (_entries)
                return _entries;
        }

        protected override StatusType getStatus()
        {
            return StatusType.Completed;
        }

        public override IEnumerable<Link> GetLinks()
        {
            yield break;
        }

        public void AddEntry(Entry entry)
        {
            lock (_entries)
                _entries.Add(entry);
        }

        public void RemoveEntry(Entry entry)
        {
            lock (_entries)
                if (_entries.Contains(entry))
                    _entries.Remove(entry);
        }

        #endregion

        #region Data

        private List<Entry> _entries;

        #endregion

        #region Public Properties

        #endregion


    }
}
